<?php

namespace App\Services\System;

use App\Exceptions\ApiException;
use ruoyi\admin\constant\Constants;
use Illuminate\Support\Facades\Cache;
use App\Models\System\SysUserModel;
use ruoyi\admin\Utils;

class CaptchaService {

    public function validateCode($uuid, $code, $precallback=null) {
        if (config('admin.admin_catpcha')) {
            if (!Cache::has('captcha_' . md5($uuid))) {
                $msg = '验证码失效';
            } else if (!captcha_api_check($code, $uuid)) {
                $msg = '验证码错误';
            }
            if(isset($msg)) {
                $precallback && $precallback($msg);
                ApiException::throw_str($msg);
            }
        }
    } 

}
